package hczc.longcai.com.hccrowdfunding.home.fourth_mine.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;
import hczc.longcai.com.hccrowdfunding.home.fourth_mine.beans.RedPacket;

/**
 * Created by Administrator on 2016/1/28.
 */
public class RedPacketAdapter extends BaseAdapter {

    private Context context;
    private List<RedPacket> list;

    public RedPacketAdapter(Context context, List<RedPacket> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_red_packet,null);
            BaseApplication.scaleScreenHelper.loadView(((ViewGroup) convertView));
            holder.type = ((TextView) convertView.findViewById(R.id.red_packet_title));
            holder.date = ((TextView) convertView.findViewById(R.id.red_packet_date));
            holder.change = ((TextView) convertView.findViewById(R.id.red_packet_state));
            convertView.setTag(holder);

        }
        holder = ((ViewHolder) convertView.getTag());
        holder.type.setText(list.get(position).getType());
        holder.date.setText(list.get(position).getDate());
        holder.change.setText(list.get(position).getChange());

        return convertView;
    }

    class ViewHolder{
        TextView type,date,change;
    }
}
